package com.neulogistics.core.substation.api.application.converter;

import cn.hutool.json.JSONUtil;
import com.neulogistics.core.substation.api.application.viewmodel.SubstationViewModel;
import com.neulogistics.core.substation.domain.model.valueobject.Address;
import com.neulogistics.core.substation.infrastructure.persistence.orm.po.SubstationPO;
import org.springframework.beans.BeanUtils;

public class SubstationPOVMConverter {
    private static final int Rate = 100;

    public static SubstationViewModel POToVM(SubstationPO substationPO){
        if (substationPO == null)
            return null;

        SubstationViewModel substationViewModel = new SubstationViewModel();
        BeanUtils.copyProperties(substationPO, substationViewModel);
        // json对象转换
        substationViewModel.setSubstationAddress(JSONUtil.toBean(substationPO.getSubstationAddress(), Address.class));

        return substationViewModel;
    }
}
